package com.ruoyi.amuse.members.controller;


import com.ruoyi.amuse.members.domain.ClubMembers;
import com.ruoyi.amuse.members.service.IClubMembersService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 社团成员Controller
 * 
 * @author juwujie
 * @date 2024-07-19
 */
@RestController
@RequestMapping("/members/members")
public class ClubMembersController extends BaseController
{
    @Autowired
    private IClubMembersService clubMembersService;

    /**
     * 查询社团成员列表
     */
    @RequiresPermissions("members:members:list")
    @GetMapping("/list")
    public TableDataInfo list(ClubMembers clubMembers)
    {
        startPage();
        List<ClubMembers> list = clubMembersService.selectClubMembersList(clubMembers);
        return getDataTable(list);
    }

    /**
     * 导出社团成员列表
     */
    @RequiresPermissions("members:members:export")
    @Log(title = "社团成员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ClubMembers clubMembers)
    {
        List<ClubMembers> list = clubMembersService.selectClubMembersList(clubMembers);
        ExcelUtil<ClubMembers> util = new ExcelUtil<ClubMembers>(ClubMembers.class);
        util.exportExcel(response, list, "社团成员数据");
    }

    /**
     * 获取社团成员详细信息
     */
    @RequiresPermissions("members:members:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(clubMembersService.selectClubMembersById(id));
    }

    /**
     * 新增社团成员
     */
    @RequiresPermissions("members:members:add")
    @Log(title = "社团成员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClubMembers clubMembers)
    {
        return toAjax(clubMembersService.insertClubMembers(clubMembers));
    }

    /**
     * 修改社团成员
     */
    @RequiresPermissions("members:members:edit")
    @Log(title = "社团成员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ClubMembers clubMembers)
    {
        return toAjax(clubMembersService.updateClubMembers(clubMembers));
    }

    /**
     * 删除社团成员
     */
    @RequiresPermissions("members:members:remove")
    @Log(title = "社团成员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(clubMembersService.deleteClubMembersByIds(ids));
    }
}
